package com.designpatterns.singletonpattern.lazy_dcl;

//双检锁/双重校验锁（DCL，即 double-checked locking）
//安全且在多线程情况下能保持高性能
public class Singleton
{
	// 一重锁
	private volatile static Singleton singleton;

	private Singleton()
	{
	}

	public static Singleton getSingleton()
	{
		if (singleton == null)
		{ // 二重锁
			synchronized (Singleton.class)
			{
				if (singleton == null)
				{
					singleton = new Singleton();
				}
			}
		}
		return singleton;
	}
}
